package com.xhd.base.obj;

import java.lang.reflect.Field;
import java.util.Hashtable;
import java.util.Map;

import com.xhd.action.Action;
import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.base.session.Session;
import com.xhd.base.session.SessionClientInfo;
import com.xhd.base.session.SessionManager;
import com.xhd.base.session.SessionUserInfo;
import com.xhd.base.session.SessionVaultInfo;
import com.xhd.base.util.XDataLang;
import com.xhd.base.util.XDataSet;
import com.xhd.base.util.xBaseObj;
import com.xhd.db.BizObjProxy;
import com.xhd.db.DBCenter;
import com.xhd.db.DaoTransaction;
import com.xhd.db.XDao;
import com.xhd.exception.IllegalDataException;
import com.xhd.exception.XException;
import com.xhd.pagination.DataPaging;
import com.xhd.server.ProcessHandle;
import com.xhd.server.ProcessHandleMgr;
import com.xhd.server.ServerConfig;
import com.xhd.servlet.ClientAction;
import com.xhd.util.DataFormat;
import com.xhd.util.ObjectSerializer;

public abstract class BaseObject
	  implements xBaseObj 
	{
	  private Session jm350 = null;
	  private SessionVaultInfo jm351 = null;
	  private SessionUserInfo jm352 = null;
	  private SessionClientInfo jm353 = null;
	  private ClientAction jm354 = null;
	  private Throwable jm355 = null;
	  private ObjectSerializer jm356 = null;
	  private boolean jm357 = false;
	  private DaoTransaction jm358 = null;
	  private DBCenter jm359 = null;
	  protected xBaseObj parentObj = null;
	  public String NamePath;
	  public String Pagination;
	  public int DataLangId;
	  private DataPaging jm360 = null;
	  private XDataLang jm361 = null;
	  private static final Log jm9;
	  static Class jm10;

	  static
	  {
	    Class tmp3_0 = jm10;
	    if (tmp3_0 == null)
	    {
	    
	      try
	      {
	        BaseObject.jm10 = Class.forName("com.sinocc.base.util.BaseObject");
	      }
	      catch (ClassNotFoundException localClassNotFoundException)
	      {
	        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
	      }
	    }
	    jm9 = LogFactory.getLog(tmp3_0);
	  }

	  public String getClassName()
	  {
	    String str = super.getClass().getName();
	    if (str != null)
	    {
	      int i = str.lastIndexOf(46);
	      if (i >= 0)
	        str = str.substring(i + 1, str.length());
	      return str;
	    }
	    return null;
	  }

	  private String jm349(String paramString)
	  {
	    if (paramString != null)
	    {
	      int i = paramString.lastIndexOf(46);
	      if (i >= 0)
	        paramString = paramString.substring(i + 1, paramString.length());
	      return paramString;
	    }
	    return "";
	  }

	  public SessionClientInfo getClientInfo()
	  {
	    if ((this.jm353 == null) && (getSession() != null))
	      this.jm353 = getSession().getClientInfo();
	    return this.jm353;
	  }

	  public void setClientInfo(SessionClientInfo paramSessionClientInfo)
	  {
	    this.jm353 = paramSessionClientInfo;
	  }

	  public Throwable getThrowable()
	  {
	    return this.jm355;
	  }

	  public Session getSession()
	  {
	    if (this.jm350 == null)
	      if (this.jm352 != null)
	        this.jm350 = SessionManager.getInstance().getSessionById(this.jm352.getSessionId());
	      else
	        getParent();
	    return this.jm350;
	  }

	  public SessionUserInfo getUserInfo()
	  {
	    if ((this.jm352 == null) && (getSession() != null))
	      this.jm352 = this.jm350.getUserInfo();
	    return this.jm352;
	  }

	  public SessionVaultInfo getVaultInfo()
	  {
	    if ((this.jm351 == null) && (getSession() != null))
	      this.jm351 = this.jm350.getVaultInfo();
	    return this.jm351;
	  }

	  public void setException(Exception paramException)
	  {
	    if (paramException instanceof XException)
	      setException((XException)paramException);
	    else
	      this.jm355 = paramException;
	  }

	  public void setThrowable(Throwable paramThrowable)
	  {
	    if (paramThrowable instanceof XException)
	      setException((XException)paramThrowable);
	    else
	      this.jm355 = paramThrowable;
	  }

	  public void setException(XException paramXException)
	  {
	    if (paramXException == null)
	      return;
	    if (getUserInfo() != null)
	      paramXException.setLanguage(getUserInfo().getLangId());
	    this.jm355 = paramXException;
	  }

	  public void setSession(Session paramSession)
	  {
	    this.jm350 = paramSession;
	  }

	  public void setUserBean(SessionUserInfo paramSessionUserInfo)
	  {
	    this.jm352 = paramSessionUserInfo;
	  }

	  public void setVaultBean(SessionVaultInfo paramSessionVaultInfo)
	  {
	    this.jm351 = paramSessionVaultInfo;
	  }

	  public ObjectSerializer getXmlTool()
	  {
	    return this.jm356;
	  }

	  public void setXmlTool(ObjectSerializer paramObjectSerializer)
	  {
	    this.jm356 = paramObjectSerializer;
	  }

	  public Hashtable toHashtable()
	  {
	    BizObjProxy localBizObjProxy = new BizObjProxy(this);
	    Field[] arrayOfField = localBizObjProxy.getBizClass().getFields();
	    if ((arrayOfField == null) || (arrayOfField.length < 1))
	      return null;
	    Hashtable localHashtable = new Hashtable(arrayOfField.length);
	    for (int i = 0; i < arrayOfField.length; ++i)
	    {
	      String str1 = localBizObjProxy.strFieldValue(arrayOfField[i]);
	      if (str1 == null)
	        continue;
	      String str2 = jm349(arrayOfField[i].getName().toLowerCase());
	      localHashtable.put(str2, str1);
	    }
	    return localHashtable;
	  }

	  public Hashtable toHashtable(String paramString)
	  {
	    if ((paramString == null) || (paramString.length() < 1))
	      return null;
	    BizObjProxy localBizObjProxy = new BizObjProxy(this);
	    String[] arrayOfString = DataFormat.splitString(paramString, ",");
	    Hashtable localHashtable = new Hashtable(arrayOfString.length);
	    for (int i = 0; i < arrayOfString.length; ++i)
	    {
	      String str = localBizObjProxy.strFieldValue(arrayOfString[i]);
	      if (str == null)
	        continue;
	      localHashtable.put(arrayOfString[i], str);
	    }
	    return localHashtable;
	  }

	  public void toObject(Map paramMap)
	    throws IllegalDataException
	  {
	    if ((paramMap == null) || (paramMap.size() < 1))
	      return;
	    BizObjProxy localBizObjProxy = new BizObjProxy(this);
	    Field[] arrayOfField = localBizObjProxy.getBizClass().getFields();
	    if ((arrayOfField == null) || (arrayOfField.length < 1))
	      return;
	    for (int i = 0; i < arrayOfField.length; ++i)
	    {
	      Field localField = arrayOfField[i];
	      String str = localField.getName().toLowerCase();
	      Object localObject = paramMap.get(str);
	      if (localObject == null)
	        continue;
	      localBizObjProxy.setFieldValue(localField, localObject);
	    }
	  }

	  public void toObject(Map paramMap, String paramString)
	    throws IllegalDataException
	  {
	    if ((paramMap == null) || (paramMap.size() < 1) || (paramString == null) || (paramString.length() < 1))
	      return;
	    BizObjProxy localBizObjProxy = new BizObjProxy(this);
	    String[] arrayOfString = DataFormat.splitString(paramString, ",");
	    for (int i = 0; i < arrayOfString.length; ++i)
	    {
	      String str1 = arrayOfString[i].toLowerCase();
	      String str2 = (String)paramMap.get(str1);
	      if (str2 == null)
	        continue;
	      localBizObjProxy.setFieldValue(str1, str2);
	    }
	  }

	  public void setEntrance()
	  {
	    this.jm357 = true;
	  }

	  public boolean isEntrance()
	  {
	    return this.jm357;
	  }

	  public ClientAction getClientAction()
	  {
	    if ((this.jm354 == null) && (this.parentObj != null))
	      return this.parentObj.getClientAction();
	    return this.jm354;
	  }

	  public void setClientAction(ClientAction paramClientAction)
	  {
	    this.jm354 = paramClientAction;
	  }

	  public XDataSet getToClientDataSet()
	  {
	    return null;
	  }

	  public xBaseObj getParent()
	  {
	    if (this.parentObj != null)
	      return this.parentObj;
	    if (isEntrance())
	      return this;
	    ProcessHandle localProcessHandle = ProcessHandleMgr.getHandle();
	    if (localProcessHandle != null)
	      setParent(localProcessHandle.getBizObj());
	    return this.parentObj;
	  }

	  public void setParent(xBaseObj paramxBaseObj)
	  {
	    this.parentObj = paramxBaseObj;
	    if (paramxBaseObj == null)
	      return;
	    this.jm358 = paramxBaseObj.getDaoTransaction();
	    this.jm359 = paramxBaseObj.getDao();
	    this.jm350 = paramxBaseObj.getSession();
	    this.jm351 = paramxBaseObj.getVaultInfo();
	    this.jm352 = paramxBaseObj.getUserInfo();
	  }

	  public DBCenter getDao()
	  {
	    if (this.jm359 == null)
	      if (isEntrance())
	        if (getVaultInfo() != null)
	        {
	          this.jm359 = new XDao(this, getVaultInfo().getVaultId());
	          getDaoTransaction().add(this.jm359, "@");
	          this.jm359.setTransation(getDaoTransaction().isUsedTransation(this.jm359));
	        }
	        else
	        {
	          jm9.error("getDBCenter not VaultInfo.");
	        }
	      else if ((getParent() != null) && (getParent() != this))
	        this.jm359 = getParent().getDao();
	    return this.jm359;
	  }

	  public void setDao(DBCenter paramDBCenter)
	  {
	    this.jm359 = paramDBCenter;
	  }

	  public Class findForwardClass(Action paramAction)
	  {
	    return null;
	  }

	  public DaoTransaction getDaoTransaction()
	  {
	    if (this.jm358 == null)
	      if (isEntrance())
	        this.jm358 = new DaoTransaction();
	      else if ((getParent() != null) && (getParent() != this))
	        this.jm358 = getParent().getDaoTransaction();
	    return this.jm358;
	  }

	  public void setDaoTransaction(DaoTransaction paramDaoTransaction)
	  {
	    this.jm358 = paramDaoTransaction;
	  }

	  public String getNamePath()
	  {
	    return this.NamePath;
	  }

	  public void setNamePath(String paramString)
	  {
	    this.NamePath = paramString;
	  }

	  public boolean isIgnoreDaoQueryRule()
	  {
	    return false;
	  }

	  public DataPaging getPagination()
	  {
	    if ((this.Pagination == null) || (this.Pagination.length() < 1))
	      return null;
	    if (this.jm360 != null)
	      return this.jm360;
	    this.jm360 = new DataPaging(this.Pagination);
	    if (this.jm360.getPageSize() < 1)
	    {
	      this.Pagination = null;
	      this.jm360 = null;
	    }
	    return this.jm360;
	  }

	  public void setPagination(DataPaging paramDataPaging)
	  {
	    this.jm360 = paramDataPaging;
	    if (paramDataPaging != null)
	      this.Pagination = paramDataPaging.toString();
	    else
	      this.Pagination = null;
	  }

	  public XDataLang getDataLang()
	  {
	    if (this.jm361 != null)
	      return this.jm361;
	    if ((ServerConfig.SupportDataMultiLang) && (XDataLang.isMultiLang(this)))
	      this.jm361 = new XDataLang(this);
	    return this.jm361;
	  }

	  public int getDataLangId()
	  {
	    if (this.DataLangId == 0)
	      this.DataLangId = getUserInfo().getLangId();
	    return this.DataLangId;
	  }
}
